<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Monolog\Logger;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Cache;
use App\Repository\Orders\OrdersRepository;

class VeriController extends Controller
{
  private $log = null;
  private $model = null;
  private $setIp;
  public function __construct(Request $request)
  {
    $this->log = new Logger('TestChannel');
    $this->log->pushHandler(
      (new RotatingFileHandler(storage_path('/logs/TestChannel.log'), 14, Logger::DEBUG, true, 0777))->setFormatter(new LineFormatter(null, null, true, true))
    );
    parent::__construct(); //app('redirect')
    ini_set('max_execution_time', 300);
    $this->setIp = 'test_channel_ip_set';
  }
  // 队列启动  徐默认启动
  public function index(Request $request){
    $ip = $request->ip();
    if(empty($ip)){
      return $this->returnMsg(100,'ip为空');
    }
    $getIp = Cache::get($this->setIp);
    if($ip != $getIp){
      return $this->returnMsg(102,'ip过期');
    }
    $where = [
      'ordersno' => $request->get('ordersno'),
    ];
    $model = new OrdersRepository();
    $res = $model ->getOne($where,['pay_identity']);
    // var_dump($ip);
    return $res;
  }
  public function setIp(Request $request){
    $ip= $request->get('ip');
    if(empty($ip)){
      return $this->returnMsg(100,'ip为空');
    }
    Cache::forever($this->setIp, $ip);
    return $this->returnMsg(200,'设置成功');
  }
  
}
